<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->
    
        <meta name="description" content="随着图像识别和深度学习领域的迅猛发展，GPU时代即将来临。由于GPU处理深度学习算法的高效性，使得配置一台搭载有GPU的服务器变得尤为必要。本文主要介绍在Ubuntu 16.04环境下如何配置TensorFlow(GPU support)框架，实验所用的显卡为GeForce GTX 1080ti(O">
    

    <!--Author-->
    
        <meta name="author" content="wangduo">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="Ubuntu 16.04 + CUDA 8.0 + cuDNN v5.1 + TensorFlow(GPU support)安装配置详解"/>
    

    <!--Open Graph Description-->
    

    <!--Open Graph Site Name-->
    <meta property="og:site_name" content="wangduo"/>

    <!--Type page-->
    
        <meta property="og:type" content="article" />
    

    <!--Page Cover-->
    

        <meta name="twitter:card" content="summary" />
    

    <!-- Title -->
    
    <title>Ubuntu 16.04 + CUDA 8.0 + cuDNN v5.1 + TensorFlow(GPU support)安装配置详解 - wangduo</title>

    <!-- Bootstrap Core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/style.css">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet" />

    <!-- Google Analytics -->
    


    <!-- favicon -->
    
	
</head>


<body>

    <!-- Menu -->
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">wangduo's blog</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                
                    <li>
                        <a href="/">
                            
                                Home
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/archives">
                            
                                Archives
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/tags">
                            
                                Tags
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/categories">
                            
                                Categories
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/about">
                            
                                About
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="https://github.com/wduo">
                            
                                <i class="fa fa-github fa-stack-2x"></i>
                            
                        </a>
                    </li>
                
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <!-- Main Content -->
    <!-- Page Header -->
<!-- Set your background image for this header in your post front-matter: cover -->

<header class="intro-header" style="background-image: url('http://ovu6dymqj.bkt.clouddn.com/20170817-cover1-VCG21gic13789852.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>Ubuntu 16.04 + CUDA 8.0 + cuDNN v5.1 + TensorFlow(GPU support)安装配置详解</h1>
                    
                    <span class="meta">
                        <!-- Date and Author -->
                        
                            Posted by wangduo on
                        
                        
                            2017-08-17
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Tags and categories -->
           
                <div class="col-lg-4 col-lg-offset-2 col-md-5 col-md-offset-1 post-tags">
                    
                        


<a href="/tags/TensorFlow/">#TensorFlow</a> <a href="/tags/GPU-support/">#GPU support</a> <a href="/tags/Ubuntu-16-04/">#Ubuntu 16.04</a> <a href="/tags/CUDA-8-0/">#CUDA 8.0</a> <a href="/tags/cuDNN-v5-1/">#cuDNN v5.1</a>


                    
                </div>
                <div class="col-lg-4 col-md-5 post-categories">
                    
                        

<a href="/categories/Deep-learning/">Deep learning</a>

                    
                </div>
            

            <!-- Gallery -->
            

            <!-- Post Main Content -->
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <p>随着图像识别和深度学习领域的迅猛发展，GPU时代即将来临。由于GPU处理深度学习算法的高效性，使得配置一台搭载有GPU的服务器变得尤为必要。<br>本文主要介绍在Ubuntu 16.04环境下如何配置TensorFlow(GPU support)框架，实验所用的显卡为GeForce GTX 1080ti(OC)，显存11G，频率1569-1708MHz，CUDA核心3584个，Compute Capability为6.1。下面详细介绍安装配置的各个步骤。</p>
<p>关于本人实验室所用硬件的配置清单，请访问<a href="http://www.cnblogs.com/wangduo/p/7383860.html" target="_blank" rel="external">深度学习硬件购买指南</a>。</p>
<h3 id="1-安装Ubuntu-16-04"><a href="#1-安装Ubuntu-16-04" class="headerlink" title="1.安装Ubuntu 16.04"></a>1.安装Ubuntu 16.04</h3><p>本文中，我们将安装Win 10 pro+Ubuntu 16.04 LTS双系统。系统安装的教程网上铺天盖地，在此不再详述。给出两个教程链接供大家参考：<br><a href="http://jingyan.baidu.com/article/d5c4b52bc0ae1fda560dc5ac.html" target="_blank" rel="external">http://jingyan.baidu.com/article/d5c4b52bc0ae1fda560dc5ac.html</a><br><a href="http://jingyan.baidu.com/article/dca1fa6fa3b905f1a44052bd.html" target="_blank" rel="external">http://jingyan.baidu.com/article/dca1fa6fa3b905f1a44052bd.html</a><br>建议使用Universal USB Installer，简单小巧易用。本实验的Ubuntu 16.04的分区大小及设置如下（仅供参考）：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">boot 主分区 Ext4 8192MB(8G)</div><div class="line">/ 逻辑分区 Ext4 81920MB(80G)</div><div class="line">/home 逻辑分区 Ext4 153600MB(150G)</div><div class="line">swap 逻辑分区 8192MB(8G)</div></pre></td></tr></table></figure></p>
<p>安装完成后，登录Ubuntu 16.04系统，若进入grub rescue模式，请参考如下方法修复grub：<br><a href="http://yhz61010.iteye.com/blog/2302418" target="_blank" rel="external">http://yhz61010.iteye.com/blog/2302418</a><br>修复完grub后，若无法开机或开机黑屏，请参考如下方法解决：<br><a href="http://blog.csdn.net/Good_Day_Day/article/details/74352534" target="_blank" rel="external">http://blog.csdn.net/Good_Day_Day/article/details/74352534</a></p>
<h4 id="1-1安装NVIDIA驱动程序"><a href="#1-1安装NVIDIA驱动程序" class="headerlink" title="1.1安装NVIDIA驱动程序"></a>1.1安装NVIDIA驱动程序</h4><p>NVIDIA 驱动程序下载链接：<br><a href="http://www.nvidia.cn/Download/index.aspx" target="_blank" rel="external">http://www.nvidia.cn/Download/index.aspx</a></p>
<h5 id="1-1-1-For-Win-10-pro："><a href="#1-1-1-For-Win-10-pro：" class="headerlink" title="1.1.1 For Win 10 pro："></a>1.1.1 For Win 10 pro：</h5><p>点击上面链接进入下载页面，选择合适版本下载并安装，或直接安装驱动精灵更新系统驱动。安装过程中若出现兼容性问题，请按win+i进入设置中更新系统。<br>驱动安装完成后，可以在Windows系统中检测硬件性能，检测软件有：AS SSD Benchmark; cpu-z; techpowerup gpu-z; 3d mark; Furamrk等。</p>
<h5 id="1-1-2-For-Ubuntu-16-04："><a href="#1-1-2-For-Ubuntu-16-04：" class="headerlink" title="1.1.2 For Ubuntu 16.04："></a>1.1.2 For Ubuntu 16.04：</h5><p>点击上面链接进入下载页面，选择合适版本下载。安装方法请参考如下两个链接：<br><a href="http://blog.csdn.net/tianrolin/article/details/52830422" target="_blank" rel="external">http://blog.csdn.net/tianrolin/article/details/52830422</a><br><a href="http://blog.csdn.net/u012581999/article/details/52433609" target="_blank" rel="external">http://blog.csdn.net/u012581999/article/details/52433609</a></p>
<h3 id="2-Requirements-to-run-TensorFlow-with-GPU-support"><a href="#2-Requirements-to-run-TensorFlow-with-GPU-support" class="headerlink" title="2.Requirements to run TensorFlow with GPU support"></a>2.Requirements to run TensorFlow with GPU support</h3><h4 id="2-1安装CUDA-8-0"><a href="#2-1安装CUDA-8-0" class="headerlink" title="2.1安装CUDA 8.0"></a>2.1安装CUDA 8.0</h4><p>下载CUDA 8.0：<br><a href="https://developer.nvidia.com/cuda-downloads" target="_blank" rel="external">https://developer.nvidia.com/cuda-downloads</a><br>Installing from a deb File:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"># 1.Install kernel headers and development packages for the currently running kernel</div><div class="line">$ sudo apt-get install linux-headers-$(uname -r)</div><div class="line"># 2.Install repository meta-data</div><div class="line">$ sudo dpkg -i cuda-repo-&lt;distro&gt;_&lt;version&gt;_&lt;architecture&gt;.deb</div><div class="line"># 3.Update the Apt repository cache</div><div class="line">$ sudo apt-get update</div><div class="line"># 4.Install CUDA</div><div class="line">$ sudo apt-get install cuda</div></pre></td></tr></table></figure></p>
<p>测试CUDA 8.0是否安装成功，请参考CUDA 8.0官方教程：<br><a href="http://docs.nvidia.com/cuda/cuda-installation-guide-linux/#recommended-post" target="_blank" rel="external">http://docs.nvidia.com/cuda/cuda-installation-guide-linux/#recommended-post</a><br>请在<em>2.3配置环境变量</em>后进行测试。</p>
<h5 id="2-1-1-gcc版本降级"><a href="#2-1-1-gcc版本降级" class="headerlink" title="2.1.1 gcc版本降级"></a>2.1.1 gcc版本降级</h5><p>Ubuntu 16.04的gcc编译器是5.4.0，然而CUDA 8.0不支持5.0以上的编译器，因此需要降级，把编译器版本降到4.9。命令如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">sudo apt-get install g++-4.9</div><div class="line">sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20</div><div class="line">sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10</div><div class="line">sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20</div><div class="line">sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10</div><div class="line">sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30</div><div class="line">sudo update-alternatives --set cc /usr/bin/gcc</div><div class="line">sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30</div><div class="line">sudo update-alternatives --set c++ /usr/bin/g++</div></pre></td></tr></table></figure></p>
<p>顺便科普一下如何查看Ubuntu 16.04的Kernel，GCC和GLIBC的版本信息。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"># Kernel: </div><div class="line">$ uname -sr #或</div><div class="line">$ uname -r</div><div class="line"># GCC</div><div class="line">$ gcc -v #或</div><div class="line">$ gcc --version</div><div class="line"># GLIBC</div><div class="line">$ ldd --version</div></pre></td></tr></table></figure></p>
<h4 id="2-2-安装cuDNN-v5-1"><a href="#2-2-安装cuDNN-v5-1" class="headerlink" title="2.2.安装cuDNN v5.1"></a>2.2.安装cuDNN v5.1</h4><p>下载cuDNN v5.1（需要注册并填写一个简单的问卷调查）：<br><a href="https://developer.nvidia.com/cudnn" target="_blank" rel="external">https://developer.nvidia.com/cudnn</a><br>Installing from a Tar File:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"># 1.Navigate to your &lt;installpath&gt; directory containing cuDNN.</div><div class="line"># 2.Unzip the cuDNN package.</div><div class="line">$ tar -xzvf cudnn-9.0-linux-x64-v7.tgz</div><div class="line"># 3.Copy the following files into the CUDA Toolkit directory.</div><div class="line">$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include</div><div class="line">$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64</div><div class="line">$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*</div><div class="line"># 4.更新软连接</div><div class="line">$ cd /usr/local/cuda/lib64/</div><div class="line">$ sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件</div><div class="line">$ sudo ln -s libcudnn.so.5.1.5 libcudnn.so.5 #生成软衔接</div><div class="line">$ sudo ln -s libcudnn.so.5 libcudnn.so #生成软链接</div></pre></td></tr></table></figure></p>
<h4 id="2-3-配置环境变量"><a href="#2-3-配置环境变量" class="headerlink" title="2.3 配置环境变量"></a>2.3 配置环境变量</h4><p>在终端输入：<br><code>$ sudo gedit ~/.bashrc #打开.bashrc文件</code><br>在此文件末尾加入如下环境变量设置语句：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">export CUDA_HOME=/usr/local/cuda-8.0</div><div class="line">export PATH=/usr/local/cuda-8.0/bin$&#123;PATH:+:$&#123;PATH&#125;&#125;</div><div class="line">export LD_LIBRARY_PATH=&quot;$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/extras/CUPTI/lib64:~/cuDNN_installpath&quot;</div></pre></td></tr></table></figure></p>
<p>使设置立即生效，在终端执行：<br><code>$ source ~/.bashrc</code><br>或者重启电脑即可。</p>
<h4 id="2-4-Install-Bazel"><a href="#2-4-Install-Bazel" class="headerlink" title="2.4 Install Bazel"></a>2.4 Install Bazel</h4><p>If bazel is not installed on your system, install it now by following these directions.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"># 1. Install JDK 8</div><div class="line">$ sudo apt-get install openjdk-8-jdk</div><div class="line"># 2. Add Bazel distribution URI as a package source (one time setup)</div><div class="line">$ echo &quot;deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8&quot; | sudo tee /etc/apt/sources.list.d/bazel.list</div><div class="line">$ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -</div><div class="line"># 3.Install and update Bazel</div><div class="line">$ sudo apt-get update &amp;&amp; sudo apt-get install bazel</div><div class="line"># Once installed, you can upgrade to a newer version of Bazel with:</div><div class="line">$ sudo apt-get upgrade bazel</div></pre></td></tr></table></figure></p>
<p>参考链接：<br><a href="https://bazel.build/versions/master/docs/install.html" target="_blank" rel="external">https://bazel.build/versions/master/docs/install.html</a><br>若需要安装curl，请按提示安装：<br><code>$ sudo apt-get install curl</code></p>
<h4 id="2-5-Install-TensorFlow-Python-dependencies-and-libcupti-dev"><a href="#2-5-Install-TensorFlow-Python-dependencies-and-libcupti-dev" class="headerlink" title="2.5 Install TensorFlow Python dependencies and libcupti-dev"></a>2.5 Install TensorFlow Python dependencies and libcupti-dev</h4><p>To install these packages for Python 3.n, issue the following command:<br><code>$ sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel</code><br>You must also install libcupti-dev by invoking the following command:<br><code>$ sudo apt-get install libcupti-dev</code></p>
<p>Ubuntu 16.04的默认python版本是2.*，关于如何将python从2.*升级到3.*，请自行查资料解决。</p>
<h3 id="3-安装TensorFlow-GPU-support"><a href="#3-安装TensorFlow-GPU-support" class="headerlink" title="3.安装TensorFlow(GPU support)"></a>3.安装TensorFlow(GPU support)</h3><h4 id="3-1-Clone-the-TensorFlow-repository"><a href="#3-1-Clone-the-TensorFlow-repository" class="headerlink" title="3.1 Clone the TensorFlow repository"></a>3.1 Clone the TensorFlow repository</h4><p>To clone the latest TensorFlow repository, issue the following command:<br><code>$ git clone https://github.com/tensorflow/tensorflow</code></p>
<p>关于git的使用方法，请参考<a href="http://www.cnblogs.com/wangduo/p/6627924.html" target="_blank" rel="external">Git学习笔记</a>。</p>
<h4 id="3-2-Configure-the-installation"><a href="#3-2-Configure-the-installation" class="headerlink" title="3.2 Configure the installation"></a>3.2 Configure the installation</h4><p>配置安装命令如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ cd tensorflow  # cd to the top-level directory created</div><div class="line">$ ./configure</div></pre></td></tr></table></figure></p>
<p>Here is an example execution of the configure script. Note that your own input will likely differ from our sample input：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line">Please specify the location of python. [Default is /usr/bin/python]:</div><div class="line">Please specify optimization flags to use during compilation when bazel option &quot;--config=opt&quot; is specified [Default is -march=native]:</div><div class="line">Do you wish to use jemalloc as the malloc implementation? [Y/n]</div><div class="line">jemalloc enabled</div><div class="line">Do you wish to build TensorFlow with Google Cloud Platform support? [y/N]</div><div class="line">No Google Cloud Platform support will be enabled for TensorFlow</div><div class="line">Do you wish to build TensorFlow with Hadoop File System support? [y/N]</div><div class="line">No Hadoop File System support will be enabled for TensorFlow</div><div class="line">Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]</div><div class="line">No XLA JIT support will be enabled for TensorFlow</div><div class="line">Found possible Python library paths:</div><div class="line">  /usr/local/lib/python2.7/dist-packages</div><div class="line">  /usr/lib/python2.7/dist-packages</div><div class="line">Please input the desired Python library path to use. Default is [/usr/local/lib/python2.7/dist-packages]</div><div class="line">Using python library path: /usr/local/lib/python2.7/dist-packages</div><div class="line">Do you wish to build TensorFlow with OpenCL support? [y/N] N</div><div class="line">No OpenCL support will be enabled for TensorFlow</div><div class="line">Do you wish to build TensorFlow with CUDA support? [y/N] Y</div><div class="line">CUDA support will be enabled for TensorFlow</div><div class="line">Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:</div><div class="line">Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0</div><div class="line">Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:</div><div class="line">Please specify the cuDNN version you want to use. [Leave empty to use system default]: 5</div><div class="line">Please specify the location where cuDNN 5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:</div><div class="line">Please specify a list of comma-separated Cuda compute capabilities you want to build with.</div><div class="line">You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.</div><div class="line">Please note that each additional compute capability significantly increases your build time and binary size.</div><div class="line">[Default is: &quot;3.5,5.2&quot;]: 6.1</div><div class="line">Setting up Cuda include</div><div class="line">Setting up Cuda lib</div><div class="line">Setting up Cuda bin</div><div class="line">Setting up Cuda nvvm</div><div class="line">Setting up CUPTI include</div><div class="line">Setting up CUPTI lib64</div><div class="line">Configuration finished</div></pre></td></tr></table></figure></p>
<p>可在配置前先执行<code>bazel clean</code>，避免与其他配置冲突。</p>
<h4 id="3-3-Build-the-pip-package"><a href="#3-3-Build-the-pip-package" class="headerlink" title="3.3 Build the pip package"></a>3.3 Build the pip package</h4><p>To build a pip package for TensorFlow with GPU support, invoke the following command:<br><code>$ bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package</code></p>
<p>若出现error load….错误，请在bazel build前添加sudo。执行这一步需要有耐心，如果是因为网络原因导致所需的包未成功下载，请重复执行此句。</p>
<p>The bazel build command builds a script named build_pip_package. Running this script as follows will build a .whl file within the /tmp/tensorflow_pkg directory:<br><code>$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg</code></p>
<h4 id="3-4-Install-the-pip-package"><a href="#3-4-Install-the-pip-package" class="headerlink" title="3.4 Install the pip package"></a>3.4 Install the pip package</h4><p>Invoke pip install to install that pip package. The filename of the .whl file depends on your platform. For example, the following command will install the pip package.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"># for TensorFlow 1.x.x on Linux:</div><div class="line">$ sudo pip install /tmp/tensorflow_pkg/tensorflow-1.x.x-xxx....whl</div></pre></td></tr></table></figure></p>
<h4 id="3-5-Validate-your-installation"><a href="#3-5-Validate-your-installation" class="headerlink" title="3.5 Validate your installation"></a>3.5 Validate your installation</h4><p>Validate your TensorFlow installation by doing the following:<br>Start a terminal. Change directory (cd) to any directory on your system other than the tensorflow subdirectory from which you invoked the configure command.<br>Invoke python:<br><code>$ python</code><br>Enter the following short program inside the python interactive shell:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"># Python</div><div class="line">import tensorflow as tf</div><div class="line">hello = tf.constant(&apos;Hello, TensorFlow!&apos;)</div><div class="line">sess = tf.Session()</div><div class="line">print(sess.run(hello))</div></pre></td></tr></table></figure></p>
<p>If the system outputs the following, then you are ready to begin writing TensorFlow programs:<br><code>Hello, TensorFlow!</code><br>执行上述命令时，终端中会显示关于显卡的一些信息，如此则表示TensorFlow(GPU support)已正确安装。</p>
<p>另外，再给出一个验证程序。可将该程序保存为xxx.py文件，用<code>python xxx.py</code>在终端中执行。如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">import tensorflow as tf</div><div class="line"># Creates a graph.</div><div class="line">a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name=&apos;a&apos;)</div><div class="line">b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name=&apos;b&apos;)</div><div class="line">c = tf.matmul(a, b)</div><div class="line"># Creates a session with log_device_placement set to True.</div><div class="line">sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))</div><div class="line"># Runs the op.</div><div class="line">print(sess.run(c))</div></pre></td></tr></table></figure></p>
<p>其中，sess中的log_device_placement参数用来设置显示Ops所用设备的名称。如果出现错误信息，说明安装出现问题。此时，一定要有一颗坚韧不拔，坚强勇敢的心。休息一下，理清思路，再来。</p>
<h3 id="4-总结"><a href="#4-总结" class="headerlink" title="4.总结"></a>4.总结</h3><p>至此，本文已接近尾声。回顾配置该环境的过程，主要有：双系统和显卡驱动的安装，CUDA 8.0和cuDNN v5.1的安装，环境变量的配置，Bazel的安装，TensorFlow的安装配置，bazel build命令的执行等。正确配置以上步骤，即可成功地搭建所需环境。</p>
<p>如您遇到问题，可以在下方留言或发消息与博主交流。 ^_^ </p>
<p>一本正经的整理了这么多内容，下面要放纵一下自己，开始自由发挥了。 ^_^ 说实话，第一次配置这个环境很消耗内力（哥哥我也是有武功的），会遇到很多坑，会遇到各种网上都搜不到的红色的Errors。也不知道从什么时候开始，甚至有些喜欢黄色的Warning了，因为再怎么说它也不是Errors啊。当然绿色的Info是最好的了，代表安装successfully。</p>
<p>在这几天期间，无数次崩溃、无语、想抓狂，感觉一切乱如牛毛。大早上醒来就开始想流程走到了哪一步了，可能是哪里的问题，大晚上睡不着觉还在想。 (哭笑哭笑) 看官网教程看的眼快se’ia了，放眼望去，世界一片朦胧。所以准备花三万块钱治好我的近视眼，只为大老远就能看见你和你say hello（此句来自个不愿戴眼镜的近视眼）。哈哈哈，越扯越远，偏离主题了啊，停住停住，赶快停住(偷笑偷笑)……</p>
<p>所幸，最后终于成功地配置了这个环境，也学到了许多新知识。一句话，坚持不懈，坚韧不拔，坚定信念，自强不息。</p>
<h3 id="5-致谢"><a href="#5-致谢" class="headerlink" title="5.致谢"></a>5.致谢</h3><p>首先，感谢实验室各位老师在精神、物质以及其他方面的支持，特别是王老师(抱拳抱拳)。<br>王老师曾说过：人生啊，肯定是彩色的。不要总羡慕别人。不管你上的是清华北大，还是普通学校，都要有计划，不要整天不知道自己该干什么。首先要克服的就是自己，不嫉妒别人，也不嘲笑别人，有一个开阔的心胸，大学生要有这样的品质。<br>你看你看，多有诗意，多有氛围。(鼓掌鼓掌热烈鼓掌)</p>
<p>其次，感谢师兄师姐们，很想念你们。此一别，不知何时再见。每每想起，不禁泪盈满眶，泪湿满襟，泪眼盈眶。（大哭）愿安好……<br>哎哎哎，别入戏太深啊，镜头快转回来。哈哈哈。发现我表演能力较强，其实我很想往这方面发展的。<br>另外，师兄师姐们，我霸占了你们所有人的位置(坏笑)，有用作午休的位置，有用作吃饭的位置，有用作装机的位置，有用作放配件的位置……哈哈，不过等到新学期，新师弟师妹们一来，我的自由空间就没了。</p>
<p>再次，感谢实验室的所用同学们，感谢大家在此期间的包容和关怀。特别是yiqi师弟，没有yiqi师弟和我的互帮互助，就不会这么顺利地配置好所需的软硬件环境。</p>
<p>最后，感谢自己，感谢自己的坚持和努力。还是那句话：坚持不懈，坚韧不拔，坚定信念，自强不息。</p>
<h3 id="6-参考文献"><a href="#6-参考文献" class="headerlink" title="6.参考文献"></a>6.参考文献</h3><p>1.<a href="https://www.tensorflow.org/install/install_sources" target="_blank" rel="external">https://www.tensorflow.org/install/install_sources</a><br>2.<a href="http://docs.nvidia.com/cuda/cuda-installation-guide-linux/" target="_blank" rel="external">http://docs.nvidia.com/cuda/cuda-installation-guide-linux/</a><br>3.<a href="http://blog.csdn.net/zhaoyu106/article/details/52793183/" target="_blank" rel="external">http://blog.csdn.net/zhaoyu106/article/details/52793183/</a><br>4.<a href="https://developer.nvidia.com/cudnn" target="_blank" rel="external">https://developer.nvidia.com/cudnn</a><br>5.<a href="http://www.cnblogs.com/xujianqing/p/6142963.html" target="_blank" rel="external">http://www.cnblogs.com/xujianqing/p/6142963.html</a><br>6.<a href="https://docs.bazel.build/versions/master/install-ubuntu.html" target="_blank" rel="external">https://docs.bazel.build/versions/master/install-ubuntu.html</a><br>7.<a href="https://www.tensorflow.org/tutorials/using_gpu" target="_blank" rel="external">https://www.tensorflow.org/tutorials/using_gpu</a></p>
<p>(更新于20170816)</p>


                
            </div>

            <!-- Comments -->
            
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    


                </div>
            
        </div>
    </div>
</article>

    <!-- Footer -->
    <hr />

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                    

                    

                    
                        <li>
                            <a href="https://github.com/wduo" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    

                    
                        <li>
                            <a href="mailto:wangduoo2017@163.com" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-envelope-o fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    
                </ul>
                <p class="copyright text-muted">&copy; 2017 wangduo<br></p>
                <p class="copyright text-muted">Original Theme <a target="_blank" href="http://startbootstrap.com/template-overviews/clean-blog/">Clean Blog</a> from <a href="http://startbootstrap.com/" target="_blank">Start Bootstrap</a></p>
                <p class="copyright text-muted">Adapted for <a target="_blank" href="https://hexo.io/">Hexo</a> by <a href="http://www.codeblocq.com/" target="_blank">Jonathan Klughertz</a></p>
            </div>
        </div>
    </div>
</footer>


    <!-- After footer scripts -->
    
<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Bootstrap -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Disqus Comments -->



</body>

</html>